﻿FROM registry.cn-hangzhou.aliyuncs.com/zrng/dotnetaspnet:8.0 AS base
# 不使用root运行提示  couldn't open temporary file /etc/apt/sources.list.d/sedxOZ83A: Permission denied
#USER $APP_UID
WORKDIR /app
EXPOSE 8080

# 更新debian:12-slim源为 http://mirrors.aliyun.com/ 限速，这里使用中科大源： https://mirrors.ustc.edu.cn/debian/
# 设置支持导出excel
RUN sed -i 's@deb.debian.org@mirrors.ustc.edu.cn@g' /etc/apt/sources.list.d/debian.sources && \
    apt update && apt install -y tzdata libgdiplus && \
    ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll

FROM registry.cn-hangzhou.aliyuncs.com/zrng/dotnetsdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src

# 复制全局配置文件
COPY ["Directory.Build.props", "."]
COPY ["Directory.Packages.props", "."]
COPY ["NuGet.Config","."]

COPY ["src/NetByDocker/NetByDocker.csproj", "src/NetByDocker/"]
COPY ["src/NetByDocker.Domain/NetByDocker.Domain.csproj", "src/NetByDocker.Domain/"]
COPY ["src/NetByDocker.Core/NetByDocker.Core.csproj", "src/NetByDocker.Core/"]
COPY ["src/NetByDocker.Store.InMemory/NetByDocker.Store.InMemory.csproj", "src/NetByDocker.Store.InMemory/"]
COPY ["src/NetByDocker.Store.Npgsql/NetByDocker.Store.Npgsql.csproj", "src/NetByDocker.Store.Npgsql/"]
COPY ["src/NetByDocker.ServiceDefaults/NetByDocker.ServiceDefaults.csproj", "src/NetByDocker.ServiceDefaults/"]
RUN dotnet restore "src/NetByDocker/NetByDocker.csproj" --configfile ./NuGet.Config
COPY . .
WORKDIR "/src/src/NetByDocker"
RUN dotnet build "NetByDocker.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "NetByDocker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV TZ=Asia/Shanghai
ENTRYPOINT ["dotnet", "NetByDocker.dll"]
